package com.guge.sports.controller;


import com.guge.sports.entity.Areas;
import com.guge.sports.entity.Dto.Option;
import com.guge.sports.entity.Dto.StSchoolDto;
import com.guge.sports.entity.StSchool;
import com.guge.sports.service.StSchoolService;
import com.guge.sports.toolPackage.base.BaseController;
import com.guge.sports.toolPackage.utils.MyPager;
import com.guge.sports.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-09-14
 */
@Api(description = "学校接口")
@RestController
@RequestMapping("/sports/st-school")
public class StSchoolController extends BaseController<StSchool> {

    @Autowired
    private StSchoolService stSchoolService;

    @ApiOperation(value = "获取学校列表")
    @GetMapping("/getDeptNameAndDidList")
    public R getDeptNameAndDidList() {
        List<Option> options = stSchoolService.getSchoolNameAndDidList();
        return R.ok().data("depts", options);
    }

    @ApiOperation(value = "获取基础设置学校设置信息")
    @RequestMapping("/getSchoolMessageList")
    public R getSchoolMessageList(MyPager<StSchoolDto> myPager, @RequestBody(required = false) StSchoolDto stSchoolDto) {
        MyPager<StSchoolDto> options = stSchoolService.getSchoolMessageList(myPager, stSchoolDto);
        return R.ok().data("depts", options);
    }

    @ApiOperation(value = "添加学校")
    @RequestMapping("/AddSchool")
    public R AddSchool(@RequestBody StSchoolDto stSchoolDto) {
        System.out.println(stSchoolDto);
        stSchoolService.AddSchool(stSchoolDto);
        return R.ok();
    }

    @ApiOperation(value = "删除学校")
    @GetMapping("/DeleteById/{id}")
    public R DeleteSchool(@PathVariable("id") Long id) {
        stSchoolService.DeleteSchool(id);
        return R.ok();
    }

    @ApiOperation(value = "学校基础设置根据id查询")
    @GetMapping("/SelectById/{id}")
    public R SelectById(@PathVariable("id") Long id) {
        StSchoolDto stSchoolDto = stSchoolService.SelectById(id);
        return R.ok().data("school",stSchoolDto);
    }

    @ApiOperation(value = "地区列表")
    @PostMapping
    public R SelectArearsList() {
        List<Option> options = stSchoolService.SelectArearsList();
        return R.ok().data("depts", options);
    }


    @ApiOperation(value = "学校基础设置编辑")
    @PostMapping("/UpdateById")
    public R UpdateById(@RequestBody StSchoolDto stSchoolDto) {
        stSchoolService.UpdateById(stSchoolDto);
        return R.ok();
    }
}

